package pr.iceworld.fernando.providerproduct.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pr.iceworld.fernando.gatecommon.service.impl.BizService;
import pr.iceworld.fernando.gatecommon.web.BaseController;
import pr.iceworld.fernando.gatecommon.web.result.WebBaseResult;
import pr.iceworld.fernando.providerproduct.model.Product;
import pr.iceworld.fernando.providerproduct.repository.ProductRepository;

@RequestMapping("/products")
@RestController
public class ProductController extends BaseController<BizService<ProductRepository, Product>, Product> {

    @GetMapping("/{id}")
    protected WebBaseResult<Product> get(@PathVariable Integer id) {
        return new WebBaseResult<Product>().success().data(biz.selectByPrimaryKey(id));
    }

    @GetMapping("/product/{name}")
    public WebBaseResult<Product> getUserByUsername(@PathVariable("name") String name) {
        Product product = new Product();
        product.setName(name);
        Product result = biz.selectOne(product);
        return new WebBaseResult<Product>().success().data(result);
    }
}
